<?php

require("../function/util.php");

$news_id 			= $_POST['news_id'];

$news_weight 			= addslashes($_POST['news_weight']);
$news_date 				= addslashes($_POST['news_date']);
$news_topic 			= addslashes($_POST['news_topic']);
$news_detail 			= addslashes($_POST['news_detail']);
$news_status 			= $_POST['news_status'];

$err_msg = "";

if (strlen(trim($news_weight)) == 0) {
    $err_msg .= "Please fill in Weight<br/>";
}

if (strlen(trim($news_date)) == 0) {
    $err_msg .= "Please fill in Date<br/>";
}

if (strlen(trim($news_topic)) == 0) {
    $err_msg .= "Please fill in Topic<br/>";
}

if (strlen(trim($news_detail)) == 0) {
    $err_msg .= "Please fill in Detail<br/>";
}

if (strlen($err_msg) == 0) 
{
	$sql = "UPDATE news
			SET news_weight ='$news_weight',
				news_date 	='$news_date',
				news_topic 	='$news_topic',
				news_detail ='$news_detail',
				news_status ='$news_status'
			WHERE news_id = '$news_id'";
	if(runSQL($sql))
	{

?>
		<script type="text/javascript">
			alert("Edit News Successful!");
				top.document.getElementById('cancel_button').click();
		</script>
<?php
	} else
	{
?>
		<script type="text/javascript">
			alert("Edit News can't not be performed right now!");
		</script>
<?php
	}
} else
{
?>
    <script type="text/javascript">
        top.document.getElementById('error').innerHTML = "<?= $err_msg ?>";
    </script>
<?php
}
?>